#! /usr/bin/env python
# _*_ coding:UTF-8 _*_
"""
@author:zhh
@Software:PyCharm
@blogs:https://blog.csdn.net/smilehaoh
@time:2020/4/10

"""
from common.connect_db import MyDB
import numpy as np

my_db = MyDB()


class Area:

    @staticmethod
    def get_old_allarea():
        """
        查询老系统地区的名称和code,deep,pid,is_old
        :return:
        """
        sql1 = "SELECT code as code1,name as name1,deep as deep1,pid as pid1  from ims_core_area where pid!=0 or pid!=null order by code desc "
        result = my_db.execute_select(select_db='old', db_name="quanfan", sql_text=sql1)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")

    @staticmethod
    def get_oldallcode():
        """
        查询老系统地区的code
        :return:
        """
        sql1 = "SELECT  code as code1 from ims_core_area "

        result = my_db.execute_select(select_db='old', db_name="quanfan", sql_text=sql1)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")

    @staticmethod
    def get_oldallname():
        """
        查询老系统地区的name
        :return:
        """
        sql1 = "SELECT  name as name1 from ims_core_area "
        result = my_db.execute_select(select_db='old', db_name="quanfan", sql_text=sql1)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")

    @staticmethod
    def get_new_allarea():
        """
       :return:
        """
        sql = "SELECT  code as code1,name as name1,level as deep1,parent_id as pid1 from common_system_areas where parent_id!=0 or parent_id!=null order by code desc"
        # sql ="SELECT  code as code1,name as name1,deep as deep1,pid as pid1,is_old as old1 from common_system_areas"
        result = my_db.execute_select(select_db='new', db_name="platformsys", sql_text=sql)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")

    @staticmethod
    def get_newallcode():
        """
       :return:
        """
        sql = "SELECT  code as code1 from ims_core_area"
        #  sql = "SELECT  code as code1 from common_system_areas"
        result = my_db.execute_select(select_db='new', db_name="migrate", sql_text=sql)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")

    @staticmethod
    def get_newallcode1():
        """
       :return:
        """
        sql = "SELECT  code as code1 from province"
        result = my_db.execute_select(select_db='new', db_name="migrate", sql_text=sql)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")

    @staticmethod
    def get_newallname():
        """
       :return:
        """
        sql = "SELECT  name as name1 from ims_core_area"
        result = my_db.execute_select(select_db='new', db_name="migrate", sql_text=sql)
        if len(result) > 0:
            return result
        else:
            raise ValueError("没有查询到相关数据")


if __name__ == '__main__':
    area = Area()
    a = area.get_new_allarea()
#  b=area.get_old_allarea()
